"""
配置管理模块
负责加载和管理系统配置
"""

import json
import logging
from pathlib import Path

logger = logging.getLogger(__name__)

class ConfigManager:
    """配置管理器"""

    def __init__(self, config_path: str = 'config.json'):
        self.config_path = config_path
        self.config = None

    def load_config(self) -> dict:
        """加载配置文件"""
        try:
            with open(self.config_path, 'r') as f:
                self.config = json.load(f)
            logger.info("配置文件加载成功")
            return self.config
        except Exception as e:
            logger.error(f"加载配置文件失败: {e}")
            raise

    def get_config(self) -> dict:
        """获取当前配置"""
        if self.config is None:
            self.load_config()
        return self.config

    def get_image_cache_dir(self) -> Path:
        """获取图片缓存目录"""
        cache_dir = Path(self.get_config()['image_service']['cache_dir'])
        cache_dir.mkdir(exist_ok=True)
        return cache_dir

# 全局配置管理器实例
config_manager = ConfigManager()
config = config_manager.load_config()
